package com.example.myapplication;



import android.graphics.Color;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;

import java.util.ArrayList;
import java.util.List;

public class MainActivity2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        BarChart barChart=findViewById(R.id.barchart);
        List<IBarDataSet> s=new ArrayList<>();

        float[] f1={10f,15f,20f,25f,30f};
        BarDataSet bar1=getBarDataSet(f1,"bar1");
        bar1.setColor(Color.parseColor("#BFEFFF"));
        s.add(bar1);

        /*float[] f2={30f,25f,15f,20f,5f};
        BarDataSet bar2=getBarDataSet(f2,"bar2");
        bar2.setColor(Color.parseColor("#68838B"));
        s.add(bar2);*/

        BarData barData=new BarData(s);
        barChart.setData(barData);
        barChart.invalidate();
    }

    private BarDataSet getBarDataSet(float[] f,String title){
        List<BarEntry> data=new ArrayList<>();
        for (int x=0;x<f.length;x++){
            BarEntry barEntry=new BarEntry(x,f[x]);
            data.add(barEntry);
        }
        return  new BarDataSet(data,title);
    }
}
